        var selfHarvestStore = new Ext.data.JsonStore({
			url: '/weihe/getSelf_harvest',
			root: 'datas',
			fields : [{
						name:'SelfHarvestId',mapping:'id'
					},{
     				   name:'SelfHarvestDate', mapping:'date',type : 'date', dateFormat:"Y-m-d H:i:s"
      			  	},{
						name:'SelfHarvestType',mapping:'type'
					},{
						name:'SelfHarvestIncome',mapping:'income'
					},{
						name:'SelfHarvestCost',mapping:'cost'
					},{
						name:'SelfHarvestFee',mapping:'fee'
				    },{
				    	name:'SelfHarvestTax',mapping:'tax'
				    },{
				    	name:'SelfHarvestBalance',mapping:'balance'
				    },{
				    	name:'SelfHarvestOther',mapping:'other'
				    },{
				    	name:'SelfHarvestLoss',mapping:'loss'
				    },{
				    	name:'SelfHarvestGrossProfit',mapping:'grossProfit'
				    },{
				    	name:'SelfHarvestNetProfit',mapping:'netProfit'
				    },{
				    	name:'SelfHarvestRate',mapping:'rate'
				    }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_harvest',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
    	
        
          var selfListStore = new Ext.data.JsonStore({
			url: '/weihe/getSelfList_harvest',
			root: 'datas',
			fields : [{
						name:'SelfListId',mapping:'id'
					},{
     				   name:'SelfListDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
      			  	},{
						name:'SelfListType',mapping:'type'
					},{
						name:'SelfListIncome',mapping:'income'
					},{
						name:'SelfListCost',mapping:'cost'
					},{
						name:'SelfListFee',mapping:'fee'
				    },{
				    	name:'SelfListTax',mapping:'tax'
				    },{
				    	name:'SelfListBalance',mapping:'balance'
				    },{
				    	name:'SelfListOther',mapping:'other'
				    },{
				    	name:'SelfListLoss',mapping:'loss'
				    },{
				    	name:'SelfListGrossProfit',mapping:'grossProfit'
				    },{
				    	name:'SelfListNetProfit',mapping:'netProfit'
				    },{
				    	name:'SelfListRate',mapping:'rate'
				    }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_harvest',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
    	
   
    	

selfHarvests = function(){
  return{
     
  	
  	 selfListGrid : function(){

		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
	    var pageToolBar = new Ext.PagingToolbar({
			pageSize : 7,
			store : selfListStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
			});
		 
	   var selfListGrid = new Ext.grid.GridPanel({
		   id:'selfListGrid',
		   title : '自营成果统计表',
		   region : 'north',
		   height :230,
		   minColumnWidth : 50,
		   tbar:["-",'查看年月:',new Ext.form.TextField({id:'year',name:'query',value:(new Date()).format('Y-m'),width:'80'}),new Ext.Button({text:'提交',handler : function() {
			   					Ext.getCmp("selfListGrid").getStore().baseParams = {'query':Ext.getCmp('year').getValue()};
			   					Ext.getCmp("selfListGrid").getStore().load({params : {start : 0, limit : 7}});
		   		}})
		   ,"-"],

		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : selfListStore,
		   columns: [
		             {header : '日期', dataIndex : 'SelfListDate', menuDisabled : true,renderer:function(value, cellmeta, record, rowIndex){
							if(value != null&&(rowIndex%6==0)){
									return value.format('Y年m月');
								}else if (value != null&&((rowIndex+1)%6==0)){
									return '本月合计';
								}else if(value == null){
									return '本年累计';
								}else{
									return "";
								}
		             }},
		             {header : '商品类别', dataIndex : 'SelfListType'},
		             {header : '销售收入', dataIndex : 'SelfListIncome'},
		             {header : '销售成本', dataIndex : 'SelfListCost'},
		             {header : '财产损益（+-）', dataIndex : 'SelfListBalance'},
		             {header : '其他支出', dataIndex : 'SelfListOther'},
		             {header : '坏账损失', dataIndex : 'SelfListLoss'},
		             {header : '毛利', dataIndex : 'SelfListGrossProfit'}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   if(record.get('SelfListType')!=""){
				 var d = record.get('SelfListDate');
				 var type = record.get('SelfListType');
			  	 Ext.getCmp("selfHarvestGrid").getStore().baseParams = {'selfHarvest.date':d,'selfHarvest.type':type};
			   	 Ext.getCmp("selfHarvestGrid").getStore().load({params : {start : 0, limit : 5}});
			   	}
			   	else{
			   		if((rowIndex+1)%6==0){
						 var d = record.get('SelfListDate');
						 Ext.getCmp("selfHarvestGrid").getStore().baseParams = null;
			  	 		Ext.getCmp("selfHarvestGrid").getStore().baseParams = {'selfHarvest.date':d};
			   	 		Ext.getCmp("selfHarvestGrid").getStore().load({params : {start : 0, limit : 5}});
					
					}else{
						Ext.Msg.alert('提示','不能查看年合计数据!');
					}
			   }
			 
			 
			 
			 
			 
			   
			 }
		   
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return selfListGrid;
	},
	
	 selfHarvestGrid : function(){

		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
	    var pageToolBar = new Ext.PagingToolbar({
			pageSize : 5,
			store : selfHarvestStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
			});
		 
	   var selfHarvestGrid = new Ext.grid.GridPanel({
		   id:'selfHarvestGrid',
		   title : '自营成果表',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : selfHarvestStore,
		   columns: [
		             {header : '日期', dataIndex : 'SelfHarvestDate',sortable : true,renderer:Ext.util.Format.dateRenderer('Y-m-d H:i:s'),width:130},
		             {header : '商品类别', dataIndex : 'SelfHarvestType'},
		             {header : '销售成本', dataIndex : 'SelfHarvestCost'},
		             {header : '财产损益（+-）', dataIndex : 'SelfHarvestBalance'},
		             {header : '其他支出', dataIndex : 'SelfHarvestOther'},
		             {header : '坏账损失', dataIndex : 'SelfHarvestLoss'}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   if(record.get('SelfHarvestType')!=""){
			   	  Ext.getCmp("selfHarvestForm").form.loadRecord(record);
			   	  Ext.getCmp("selfHarvestForm").buttons[0].setText('修改');
			   	}
			   	else{
			   		 Ext.getCmp("selfHarvestForm").form.reset();
			   		Ext.Msg.alert('提示','不能修改合计数据!');
			   	}
			   	
			   }
		   
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return selfHarvestGrid;
	},
	selfHarvestForm : function(){
		
		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
					progressConsole();
				if(selfHarvestForm.form.isValid()){ 	
					if (selfHarvestForm.form.findField("SelfHarvestId").getValue() == "") {
						selfHarvestForm.form.submit({
						  url : '/weihe/addSelf_harvest',
						   success : function(form, action) {
						   	 if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
			  							   var d = selfHarvestForm.form.findField("SelfHarvestDate").getValue();
			  	 						   Ext.getCmp("selfListGrid").getStore().baseParams = {'query':d};
			   	 						   Ext.getCmp("selfListGrid").getStore().load({params : {start : 0, limit : 7}});
										   var type = selfHarvestForm.form.findField("SelfHarvestType").getValue();
			  	 						   Ext.getCmp("selfHarvestGrid").getStore().baseParams = {'selfHarvest.date':d,'selfHarvest.type':type};
			   	 						   Ext.getCmp("selfHarvestGrid").getStore().load({params : {start : 0, limit : 5}});
									       selfHarvestForm.form.reset();
									       selfHarvestForm.form.findField("SelfHarvestDate").setValue((new Date()).format('Y-m-d H:i:s'));
								});
							  }
						    }
					    });
					}else {
						selfHarvestForm.form.submit({
							  url : '/weihe/updateSelf_harvest',
							   success : function(form, action) {
								  if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										selfHarvestForm.form.reset();
										selfHarvestForm.form.findField("SelfHarvestDate").setValue((new Date()).format('Y-m-d H:i:s'));
										Ext.getCmp("selfListGrid").getStore().reload();
										Ext.getCmp("selfHarvestGrid").getStore().reload();
										selfHarvestForm.buttons[0].setText('添加');
										
									});
								  }
							    }
						    });
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

		
		
	var button_clear = new Ext.Button({
		id : 'button_clear',
		text : '清空',
		handler : function() {
			selfHarvestForm.form.reset();
			selfHarvestForm.form.findField("SelfHarvestDate").setValue((new Date()).format('Y-m-d H:i:s'));
			selfHarvestForm.buttons[0].setText('添加');
		}
	});
	
	
	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = selfHarvestForm.form.findField('SelfHarvestId').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/deleteSelf_harvest',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							if (json.deny) {
									Ext.Msg.alert('错误',json.msg);
									selfHarvestForm.form.reset();
									selfHarvestForm.buttons[0].setText('添加');
							}else{
								Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("selfListGrid").getStore().reload();
								Ext.getCmp("selfHarvestGrid").getStore().reload();
								selfHarvestForm.form.reset();
								selfHarvestForm.form.findField("SelfHarvestDate").setValue((new Date()).format('Y-m-d H:i:s'));
								selfHarvestForm.buttons[0].setText('添加');
							});
						  }
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params : 'selfHarvest.id=' + id
				});
			}
		}
	});
	
  var typeComboData = new Ext.data.SimpleStore({
		  fields : ['text'],
		  data : [['汽车'],['摩托车'],['汽车配件'],['摩托车配件'],['其他']]
	  });
  		

	var  selfHarvestForm = new Ext.form.FormPanel({
		id : 'selfHarvestForm',
		title : '自营业务信息',
		frame : true,
		width : 300,
		region : 'east',
		autoScroll : true,
		collapseMode :'mini',
		collapsible : true,
		labelAlign : 'right',
		labelWidth : 60,
		defaultType : 'textfield',
			defaults : {
			width : 200
		},
		items : [{  
			id:'SelfHarvestId',
			xtype : 'hidden',  
			name : 'selfHarvest.id'
		},{
			id:'SelfHarvestDate',
			xtype: 'datetimefield',
			fieldLabel: '日期',
			name: 'selfHarvest.date',
			value: (new Date()).format('Y-m-d H:i:s'),
			format: 'Y-m-d H:i:s'						
		},{
			id : 'SelfHarvestType',
		    fieldLabel : '商品类别',
 			name : 'selfHarvest.type',
 			xtype : 'combo',
 			store : typeComboData,
 			emptyText : '请选择',
 			mode : 'local',
 			triggerAction : 'all',
 			editable: false,
 			displayField : 'text'
		},{
			id:'SelfHarvestCost',
			fieldLabel : '销售成本',
			name : 'selfHarvest.cost',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'SelfHarvestBalance',
			fieldLabel : '财产损益',
			name : 'selfHarvest.balance',
			regex : /^-?\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'SelfHarvestOther',
			fieldLabel : '其他支出',
			name : 'selfHarvest.other',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'SelfHarvestLoss',
			fieldLabel : '坏账损失',
			name : 'selfHarvest.loss',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		}],
		buttons : [button_add,button_clear,button_del]
	});
		return  selfHarvestForm;
	}
  }
}();








